// ActionScript file
/*
* 用户控制的接口
*/

import mx.rpc.events.ResultEvent;


//触发退票流程事件
private function unSub():void
{
	FlightService.getOperation('getBookInfo').send( userId );
	backToUnsub();
}

//获取用户已定航班信息
private function getBookInfoHandler( evt:ResultEvent ):void
{
	//响应获取航班事件，并修改控件
	bookList.dataProvider = evt.result;
}

//要退票的航班ID
private var unSubId:String;

//触发列表单击事件
//提交要获取的座位信息的航班号
private function getDetail(event:Event):void
{
	unSubId = bookList.selectedItem.id;
	unSubId = unSubId.toString();
    FlightService.getOperation('getSeatInfo').send( bookList.selectedItem.id );
}

//获取服务器返回的座位列表
private function getSeatInfoHandler( evt:ResultEvent ):void
{
	currentState="seatList";
	var bookedSeat:Array = new Array();
	bookedSeat = evt.result as Array;
	bookSeatList.dataProvider = bookedSeat;
}

//提交退票信息到服务器
//退订指定座位
private function unsubTickets():void
{
	var seat:Array = bookSeatList.selectedItems;
	var ix:int = 0;
	var seatStr:String = null;
	var quantity:int = seat.length;
	for( ix = 0 ; ix < quantity; ix++ )
	{
		if( seatStr == null )
			seatStr = seat[ix]['label'];
		else
			seatStr = seatStr + "," + seat[ix]['label'];	
	}
	FlightService.getOperation('unsubTickets').send( unSubId, seatStr, quantity );
}

//退订全部座位
private function unsubAllTickets():void
{
	FlightService.getOperation('unsubTickets').send( unSubId );
}

//处理提交之后服务器返回的信息
private function unsubTicketsHandler( evt:ResultEvent ):void
{
	CursorManager.removeBusyCursor();
	if( evt.result )
		Alert.show('退票成功,点击确定跳转到主页面','订票成功',Alert.YES,this,alertHandler,null,Alert.YES);
	else
		Alert.show('退票失败，请重新选择，或者检查网络是否连通');
}